package EDesign23;

import java.util.ArrayList;
import java.util.List;

public class HObserver {

    public interface Observer {
        void update();
    }

    public class TeacherRollCallSubject {
        private List<Observer> observers = new ArrayList<>();

        public void addObserver(Observer observer){
            observers.add(observer);
        }

        public void removeObserver(Observer observer){
            observers.remove(observer);
        }

        public void notifyObservers (){
            observers.forEach(Observer::update);
        }

    }


    public class GotoClassObserver implements Observer {
        @Override
        public void update() {
            System.out.println("老师点名了！");
            System.out.println("我要马上赶到教室去！");
        }
    }

    public class AskForHelpObserver implements Observer {
        @Override
        public void update() {
            System.out.println("老师点名了！");
            System.out.println("赶紧给XX发信息，让他替我答到！");
        }
    }

//    public class Client {
//        public static void main(String[] args) {
//            Observer studentOne = new GotoClassObserver();
//            Observer studentTwo = new AskForHelpObserver();
//
//            TeacherRollCallSubject subject = new TeacherRollCallSubject();
//            subject.addObserver(studentOne);
//            subject.addObserver(studentTwo);
//
//            subject.notifyObservers();
//        }
//    }

}
